package chattle.shared;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "false")
public class User implements Serializable {
	private static final long serialVersionUID = 1820703091873455178L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String encodedKey;

	@Persistent
	@Extension(vendorName = "datanucleus", key = "gae.pk-name", value = "true")
	private String userId;

	@Persistent
	private String nickname;

	@Persistent
	transient
	private Date lastPresence = null;
	
	@Persistent
	transient
	private Date lastPoll = null;

	public User(String userId, String nickname) {
		super();
		this.userId = userId;
		this.nickname = nickname;
	}

	@SuppressWarnings("unused")
	private User() {
	}

	public String getEncodedKey() {
		return encodedKey;
	}

	public String getUserId() {
		return userId;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public Date getLastPresence() {
		return lastPresence;
	}

	public void setLastPresence(Date lastPresence) {
		this.lastPresence = lastPresence;
	}
	
	public Date getLastPoll() {
		return lastPoll;
	}
	
	public void setLastPoll(Date lastPoll) {
		this.lastPoll = lastPoll;
	}

	@Override
	public String toString() {
		return this.getNickname();
	}

	public String printFull() {
		return encodedKey + " " + userId + " " + nickname;
	}

}
